﻿using Orleans;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace IOP.Orleans.MessageHub
{
    /// <summary>
    /// 单个消息节点
    /// </summary>
    /// <typeparam name="TMessage"></typeparam>
    public interface IMessageGrain<TMessage> : IGrainWithStringKey
        where TMessage : class
    {
        /// <summary>
        /// 订阅
        /// </summary>
        /// <param name="observer"></param>
        /// <returns></returns>
        Task Subscribe(IMessageObserver<TMessage> observer);
        /// <summary>
        /// 取消订阅
        /// </summary>
        /// <param name="observer"></param>
        /// <returns></returns>
        Task UnSubscribe(IMessageObserver<TMessage> observer);
        /// <summary>
        /// 发送消息，并发往指定监听者(通常是除了发布者自己之外的监听者)
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        Task SendMessage(TMessage message, IMessageObserver<TMessage>[] targetObserver = null);
        /// <summary>
        /// 发送健康检查
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        Task SendHealthCheck(byte[] data, IEnumerable<IMessageObserver<TMessage>> targetObserver);
        /// <summary>
        /// 判断某个监听者是否还存在
        /// </summary>
        /// <param name="observer"></param>
        /// <returns></returns>
        Task<bool> ImAlive(IMessageObserver<TMessage> observer);
        /// <summary>
        /// 判断某个监听者是否还存在
        /// </summary>
        /// <param name="observer"></param>
        /// <returns></returns>
        Task<bool> ImAlive(IGrainObserver observer);
    }
}
